package cn.chencq.moudle.sys.controller;

import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.chencq.moudle.sys.entity.SysUser;

/**
 * Controller公共组件
 * 
 * @author chenchaoqun
 * @email ccq@chencq.cn
 * @date 2018-10-22 15:41:40
 */
public abstract class AbstractController {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	protected SysUser getUser() {
		return (SysUser) SecurityUtils.getSubject().getPrincipal();
	}

	protected Long getUserId() {
		return getUser().getUserId();
	}

	public <T> T map2Bean(Map<String, Object> params, Class<T> instance) {
		T bean = null;
		try {
			bean = instance.newInstance();
			BeanUtils.populate(bean, params);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return bean;
	}
}
